﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

namespace Quản_Lý_Thư_Viện
{
    class CT_PTSDataAccess
    {
        private DataProvider _provider = new DataProvider();
        public CT_PTSDataAccess()
        {
            _provider.connect();
        }
        public void insertCTPTS(CT_PTSinfo info)
        {
            string ngaytra = info.Ngtra.Value.Month + "/" + info.Ngtra.Value.Day + "/" + info.Ngtra.Value.Year;
            string insertCommand = "insert into dbo.CT_PTS values('" + info.Loaiphi + "','" + info.Mapts + "','" + info.Masach + "')";
            _provider.executeNonQuery(insertCommand);
        }
        public void deleteCTPTS(CT_PTSinfo info)
        {
            string deleteCommand = "delete from dbo.CT_PTS where MASACH = '" + info.Masach + "'";
            _provider.executeNonQuery(deleteCommand);
        }
        public void updateCTPTS(CT_PTSinfo info)
        {
            string updateCommand = "Update dbo.CT_PTS set MASACH = '" + info.Masach + "' where MASACH = '" + info.Masach + "'";
            _provider.executeNonQuery(updateCommand);
        }
        public void deleteptsvactpts()
        {
            string deleteCommand = "Delete from dbo.CT_PTS where dbo.CT_PTS.MAPTS IN ( select dbo.PHIEUTRASACH.MAPTS from dbo.PHIEUTRASACH where MADG = '" + frmChinh.madg2 + "')";
            _provider.executeNonQuery(deleteCommand);
                
        }
        public DataTable sosachdgdatra()
        {
            return _provider.GetData("select COUNT(MASACH) from dbo.CT_PTS,dbo.PHIEUTRASACH where dbo.PHIEUTRASACH.MAPTS = dbo.CT_PTS.MAPTS and MADG = '" + frmMuonSach.madg + "'");
        }
    }
}
